package com.starleague.game;

import java.util.ArrayList;
import java.util.List;

import com.starleague.common.AbstractChildVisitable;
import com.starleague.common.IChildVisitor;

public abstract class AbstractTeam<GAME extends AbstractGame<PLAYER, ? extends AbstractTeam<GAME, PLAYER>>, PLAYER extends AbstractPlayer<GAME, ? extends AbstractTeam<GAME, PLAYER>>>
        extends AbstractChildVisitable
        implements ITeam<GAME, PLAYER>
{
    private GAME game;
    private String name;
    private final List<? extends PLAYER> playerList = new ArrayList<>();

    protected AbstractTeam(GAME game,
                           String name)
    {
        this.game = game;
        this.name = name;
    }

    protected AbstractTeam()
    {
        // For serialization
    }

    @Override
    public GAME getGame()
    {
        return this.game;
    }

    @Override
    public String getName()
    {
        return this.name;
    }

    protected void setName(String name)
    {
        this.name = name;
    }

    @Override
    public List<? extends PLAYER> getPlayers()
    {
        return this.playerList;
    }

    @Override
    public void accept(IChildVisitor visitor)
    {
        super.accept(visitor);
        visitor.visit("name", this.name);
        visitor.visit("players", this.playerList);
    }
}
